package com.zpark.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import java.util.List;

/**
 * @PackageName: com.zpark.controller
 * @ClassName: AdminController
 * @Description:
 * @author: RZS
 * @date: 2023/4/4  17:18
 */
@Controller
/**
 * 这个地方的@RequestMapping("/admin")表示作为请求该controller的父路径
 */
@RequestMapping("/admin")
public class AdminController {

    // localhost:8080/contextPath/admin/login.do
    @RequestMapping("/login.do")
    public String login(){
        return "admin_login";
    }

    @RequestMapping(value = "/reg.do", name = "admin注册功能接口")
    public String reg(){
        return "reg";
    }

    /*
        method = RequestMethod.POST
        限制请求方式
     */
    @RequestMapping(value = "all.do", method = RequestMethod.POST)
    public List<Object> findAll(){
        ArrayList<Object> list = new ArrayList<>();
        list.add("张三");
        list.add("大锤");
        System.out.println(list);

        return list;
    }

    /**
     * params = {"parm=大锤", "code"}
     * 限制请求必须包含参数
     * @param parm
     * @param code
     */
    @RequestMapping(value = "/find_by_id.do", params = {"parm=大锤", "code"})
    public void findById(String parm, String code){
        System.out.println("请求当中必须包含参数：" + parm + "--" + code);
    }

    @RequestMapping(value = "/update.do", headers = {"aaa=123"})
    public void update(){
        System.out.println("指定必须包含请求头aaa=123");
    }

    @RequestMapping("/del.do")
    public String delete(Model model){
        /**
         * 本质是将数据添加到request域对象当中
         */
        // 绑定数据到model对象当中
        model.addAttribute("model", "model类型的形参");

        return "demo01";
    }
}
